#ifndef __common_api_h_
#define __common_api_h_



#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include <time.h>
#include <assert.h>
//#include "config.h"
#include "NUC131.h"
#include "clock_api.h"
#include "timer_api.h"
#include "adc_api.h"
#include "Motor.h"
#include "gpio_api.h"
#include "HC595.h"
//#include "flash_api.h"
#include "eeprom_api.h"
#include "wdt_api.h"
#include "FM1906.h"
#include "LCD.h"


#define  u8  unsigned char
#define  u16 unsigned short
#define  u32 unsigned long

#define OIL_LEVEL_FUNCTION      1
#define PREHEAT_IN_CAN       1    //0=检测IO口   1=检测CAN总线
#define ENGINE_O3            1
#define Version_G3          1
#define OilP_Low	200
#define OilP_High	800

typedef struct
{
    unsigned char water_temp_short_count;
    unsigned char water_temp_off_count;
    unsigned char oil_level_short_count;
    unsigned char oil_level_off_count;
    unsigned char water_temp_count;
    unsigned char oil_level_count ;
    unsigned char speed_err_count;
    unsigned char engine_speed;
    unsigned char speed;
    unsigned char preheat_count;
    unsigned char oil_temp_short_count;
    unsigned char oil_temp_off_count;
    unsigned char oil_temp_count;
    unsigned char air_pre_count;
    unsigned char oil_filter_count;

    unsigned char no_can;
    unsigned char no_speed;
    unsigned char air_filter_count;
    unsigned char oil_water_count;
    unsigned char oil_pressure_count;
    unsigned char bianju_l_count;
    unsigned char bianju_h_count;
    unsigned char air_l_count;
    unsigned char air_h_count;
    unsigned char DPF_cnt;
    unsigned char DPF_STOP_cnt;
    unsigned char ecu_err_count;
    unsigned char time_zero_cnt;
    unsigned char AnQuan_cnt;
    unsigned char PARK_cnt;
}T_TIME_CNT;
extern T_TIME_CNT TIME_CNT;
typedef struct
{
    unsigned    oil_level_short :1; //油位短路e00
    unsigned    oil_level_off   :1; //油位断路e01
    unsigned    water_temp_short:1; //水温短路e02
    unsigned    water_temp_off  :1; //水温断路e03
    unsigned    no_speed_signal :1; //转速传感器无信号e04
    unsigned    oil_temp_short  :1; //油温短路e20
    unsigned    oil_temp_off    :1; //油温断路e21
    unsigned    preheat :1; //预热报警e05

    unsigned    water_temp  :1; //水温过高  e10
    unsigned    oil_level   :1; //油位过低e09
    unsigned    oil_temp    :1; //油温过高e13
    unsigned    oil_pressure:1; //机油压力
    unsigned    charge:1;       //充电
    unsigned    air_filter :1; //空滤e07
    unsigned    oil_dirty :1; //油污          e12
    unsigned    oil_water :1; //油水分离e11

    unsigned    bianju_h :1; //变矩器
    unsigned    bianju_l :1; //
    unsigned    qiya_h :1;   //气压
    unsigned    qiya_l :1;   //
    unsigned    ecu_err:1;
    unsigned    anquan :1;  //安全带检测
    unsigned    Park_ :1;  //驻车
    unsigned    :1;
}S_Alarm_Visible_flag;
extern S_Alarm_Visible_flag Alarm_Visible_flag;

extern uint8_t FaultCnt;

extern uint8_t Flag_air;
extern uint8_t Flag_water;
extern uint8_t Flag_fuel;
extern uint8_t Flag_hand;
extern uint8_t Flag_Hex;

extern uint8_t Count_Flag;
extern uint8_t Flip_Flag;
extern uint8_t Fault_Run ;
extern uint8_t ALARM_ENGINE;

extern uint8_t motorA_Flag;
extern uint8_t motorB_Flag;
extern uint16_t Time10msCnt;
extern uint16_t Time30msCnt;
extern uint16_t Time100msCnt;
extern uint16_t Time300msCnt;
extern uint16_t Time500msCnt;
extern uint16_t Time1sFlag;
extern uint16_t Time1s;
extern uint32_t Total_Work_Time;

void SYS_Init(void);
void ms10Work(void);
void ms30Work(void);
void ms100Work(void);
void ms300Work(void);
void ms500Work(void);
void secondWork(void);
void Alarm_Work(void);


#endif


















  
